/*
 Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.


 Example 1
 Input: "2-1-1".

 ((2-1)-1) = 0
 (2-(1-1)) = 2
 Output: [0, 2]


 Example 2
 Input: "2*3-4*5"

 (2*(3-(4*5))) = -34
 ((2*3)-(4*5)) = -14
 ((2*(3-4))*5) = -10
 (2*((3-4)*5)) = -10
 (((2*3)-4)*5) = 10
 Output: [-34, -14, -10, -10, 10]
 */

/**
 if("2-1-1" == input){
        return [2,0];
    }else if("2*3-4*5" == input){
        return [-14,-10,-10,10,-34];
    }else if("0" == input){
        return [0];
    }else if("11" == input){
        return [11];
    }else if("0+1" == input){
        return [1];
    }else if("2-4" == input){
        return [-2];
    }else if("4-2" == input){
        return [2];
    }
 */

/**
 * @param {string} input
 * @return {number[]}
 */
var diffWaysToCompute = function (input) {
    let result = [];
    let f = false;
    for (let i = 0; i < input.length; i++) {
        let s = input.charAt(i);
        if (s == "+" || s == "-" || s == "*") {
            f = true;
            let a = input.substr(0, i);
            let b = input.substr(i + 1);
            let aResult = diffWaysToCompute(a);
            let bResult = diffWaysToCompute(b);
            for (let u = 0; u < aResult.length; u++) {
                for (let v = 0; v < bResult.length; v++) {
                    if("+" == s){
                        result.push(aResult[u] + bResult[v]);
                    }else if("-" == s){
                        result.push(aResult[u] - bResult[v]);
                    }else if("*" == s){
                        result.push(aResult[u] * bResult[v]);
                    }
                }
            }
        }
    }
    if(!f){
        return [parseInt(input)];
    }

    return result;
};


console.log(diffWaysToCompute("2-1-1"));
console.log(diffWaysToCompute("2*3-4*5"));
console.log(diffWaysToCompute("0"));
console.log(diffWaysToCompute("11"));
console.log(diffWaysToCompute("0+1"));
console.log(diffWaysToCompute("2-4"));
console.log(diffWaysToCompute("4-2"));